﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Text;
using YouFood.Web.Model;

namespace YouFood.Web
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service1 : IService1
    {
        public void DoWork()
        {
        }

        public YouFoodEntities context = new YouFoodEntities();

        public IEnumerable<StatDto> GetStat()
        {
            var categoryCounts =
                from p in context.Orders
                group p by p.Food.Name
                into g
                select new StatDto {Name = g.Key, Count = g.Count()};

            return categoryCounts;
        }

        public double GetPerformance()
        {
            var totalprice = context.Orders.Select(x => x.Food.Price);

            return totalprice.Sum();
        }
    }
}
